/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.dao;

import java.util.Date;
import java.util.List;

import net.iwsh.core.db.DBExecutor;
import net.iwsh.core.db.ext.DialectSyntaxParser;
import net.iwsh.core.db.ext.SQLWithParams;

import com.us.usws.model.domain.video.VideoAuthLog;
import com.us.usws.model.flat.video.DOVideoAuthLog;

/**
 * DAO class
 * @author robot
 */
public class VideoAuthLogDAO {

	/**
	 * Query SQLs
	 */
	private static final String SQL_GET_TOTAL_COUNT = "select count(*) from hv_video_auth_log";

	private static final String SQL_GET_ALL_VIDEOAUTHLOGS = "select * from hv_video_auth_log";

	private static final String SQL_GET_VIDEOAUTHLOG_BY_PK = "select * from hv_video_auth_log where video_uid = ? and auth_date = ?";

	/**
	 * CUR SQLs
	 */
	private static final String SQL_INSERT_VIDEOAUTHLOG = "insert into hv_video_auth_log(video_uid,auth_date,auth_status_sid,description,auth_user_uid) values (?,?,?,?,?)";

	private static final String SQL_UPDATE_VIDEOAUTHLOG = "update hv_video_auth_log set auth_status_sid=?, description=?, auth_user_uid=? where video_uid=? and auth_date=?";

	private static final String SQL_DEL_VIDEOAUTHLOG = "delete from hv_video_auth_log where video_uid=? and auth_date=?";

	/**
	 * DBExeutor
	 */
	private DBExecutor dbe = new DBExecutor();

	/**
	 * Get Count.
	 */
	public int getTotalCount() {
		return dbe.getCount(SQL_GET_TOTAL_COUNT);
	}

	/**
	 * Get all list.
	 */
	public List<VideoAuthLog> getAllVideoAuthLogs() {
		return dbe.list(SQL_GET_ALL_VIDEOAUTHLOGS, VideoAuthLog.class);
	}

	/**
	 * Get all list by pagination.
	 */
	public List<VideoAuthLog> getVideoAuthLogs(int start, int end) {
		SQLWithParams swp = DialectSyntaxParser.getParser().getPaginationSQLWithParams(SQL_GET_ALL_VIDEOAUTHLOGS, null, start, end);
		return dbe.list(swp.getSql(), VideoAuthLog.class, swp.getParams());
	}

	/**
	 * Get VideoAuthLog by primary key.
	 */
	public VideoAuthLog getVideoAuthLog(String videoUid, Date authDate) {
		VideoAuthLog v = dbe.load(SQL_GET_VIDEOAUTHLOG_BY_PK, VideoAuthLog.class, videoUid, authDate);
		return v;
	}

	/**
	 * Insert one row.
	 */
	public String insertVideoAuthLog(DOVideoAuthLog videoAuthLog) {
		dbe.execute(SQL_INSERT_VIDEOAUTHLOG, videoAuthLog.getVideoUid(), videoAuthLog.getAuthDate(), videoAuthLog.getAuthStatusSid(),
				videoAuthLog.getDescription(), videoAuthLog.getAuthUserUid());
		return videoAuthLog.getVideoUid();
	}

	/**
	 * Update by PK.
	 */
	public void updateVideoAuthLog(DOVideoAuthLog videoAuthLog) {
		dbe.execute(SQL_UPDATE_VIDEOAUTHLOG, videoAuthLog.getAuthStatusSid(), videoAuthLog.getDescription(), videoAuthLog.getAuthUserUid(),
				videoAuthLog.getVideoUid(), videoAuthLog.getAuthDate());
	}

	/**
	 * Delete row by PK.
	 */
	public void deleteVideoAuthLog(String videoUid, Date authDate) {
		dbe.execute(SQL_DEL_VIDEOAUTHLOG, videoUid, authDate);
	}

}